package com.itheima.controller;

import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.google.gson.Gson;
import com.itheima.common.constant.RedisConstant;
import com.itheima.common.constant.RedisMessageConstant;
import com.itheima.common.utils.SmsUtil;
import com.itheima.config.RedisConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/validatecode")
public class SendSmsController {
    @Autowired
    private SmsUtil smsUtil;
    @Autowired
    private RedisTemplate redisTemplate;
    @PostMapping("/send4Order")
    public String sendSms(String telephone) {
        Map<String,Integer> templateParam = Map.of("code",123456);
        String templateParamJson = new Gson().toJson(templateParam);
        //SendSmsResponse sendSmsResponse = smsUtil.sendSms(telephone,templateParamJson);
        //sendSmsResponse.getBody().getMessage();
        redisTemplate.opsForValue().set(RedisMessageConstant.SENDTYPE_ORDER,templateParamJson,300, TimeUnit.SECONDS);
        return null;//sendSmsResponse.getBody().getMessage();
    }
}
